import Storage from 'react-native-storage';
import AsyncStorage from '@react-native-community/async-storage';
import config  from '../config';

let storageKey = config.storageKey;


export const initStorage= () => {
  global.storage = new Storage({
    size: 9999999,
    storageBackend: AsyncStorage,
    defaultExpires: null,
    enableCache: true,
    sync: {}
  });
}


export  const setItem = (key, data) => {
  return global.storage.save({
    key: storageKey + key,
    data: data,
    expires: null
  });
};

export const getItem = key => {
  return global.storage.load({
        key: storageKey + key,
        autoSync: true,
        syncInBackground: true,
        syncParams: {
          someFlag: true
        }
      })
}

export const removeItem = key => {
  return global.storage.remove({
    key: storageKey + key
  });
}

